package com.grts.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.jsqlparser.expression.operators.conditional.OrExpression;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.grts.dao.MajorBeanMapper;
import com.grts.pojo.MajorBean;
import com.grts.pojo.t_student;
import com.grts.service.IMajorService;
import com.grts.service.IStudentService;


@Controller
@RequestMapping("/student")
public class StudentControllor {
	@Resource
	private IMajorService majorService;
	@Resource
	private IStudentService iss;
	
	@RequestMapping("tosave")
	public String tosave(Map<String,Object> map){
		List<MajorBean> majorList=majorService.queryAll();
		map.put("majorList", majorList);
		return "stu";
	}
	
	@ResponseBody
	@RequestMapping("queryById")
	public List<MajorBean> queryById(Integer mid){
		System.out.println(mid);
		List<MajorBean> major=iss.queryByID(mid);
		System.out.println(major.get(0));
		return major;
	}
	
	
	@ResponseBody
	@RequestMapping("queryMId")
	public List<MajorBean> queryFatherId(Map<String,Object> map,Integer mid){
		/*System.out.println("测试");
		System.out.println(mid);*/
		List<MajorBean> mlist=iss.queryByMId(mid);
		/*for (MajorBean m : mlist) {
			System.out.println(m.getMname());
		}*/
		return mlist;
	}
	@RequestMapping("save")
	public String save(t_student s){
		System.out.println(s);
		int i=Integer.parseInt(s.getDepartment());
		String name=iss.queryNameByID(i);
		System.out.println(name);
		s.setDepartment(name);
		iss.insert(s);
		return "stu";
	}
}
